import java.io.Serializable;
import java.util.Date;
import java.util.Calendar;

//@author A0099409N
class TimeSpan implements Comparable<TimeSpan>, Serializable{

	private Calendar _start, _end;

	public TimeSpan(Date start, Date end){
		this._start = Calendar.getInstance();
		this._end = Calendar.getInstance();
		if(start!=null){
			this._start.setTime(start);
		} else{
			this._start.set(1950,1,1);
		}
		if(end!=null){
			this._end.setTime(end);
		} else {
			this._end.set(1950,1,1);
		}
	}

	@Override
	public String toString() {
		String s;
		if (isDeadline()){
			s = "Done by: " + TimeParser.printDate(_start.getTime());
		}
		else if (isMisc()){
			s = "Done by: Any time";
		}
		else{
			String startTime = TimeParser.printDate(_start.getTime());
			String endTime = TimeParser.printDate(_end.getTime());
			s = "Start Time: " + startTime + "\n" +
					"End Time: " + endTime;
		}
		return s;
	}

	@Override
	public int compareTo(TimeSpan j) {
		if (this.getStart() == null && j.getStart() == null) {
			return 0;
		}

		if(this.getStart().before(j.getStart())){
			return -1;
		} else if(this.getStart().after(j.getStart())){
			return 1;
		}
		return 0;
	}

	public Date getStart(){
		if(_start!=null){
			return _start.getTime();
		} else {
			return null;
		}
	}

	public Date getEnd(){
		if(_end!=null){
			return _end.getTime();
		} else {
			return null;
		}
	}

	public void setStart(Date st){
		this._start = Calendar.getInstance();
		this._start.setTime(st);
	}

	public void setEnd(Date et){
		this._end = Calendar.getInstance();
		this._end.setTime(et);
	}

	public boolean isEvent(){
		if(_start.get(Calendar.YEAR) != 1950 && _end.get(Calendar.YEAR)!=1950){
			return true;
		}
		return false;
	}

	public boolean isDeadline(){
		if(_start.get(Calendar.YEAR) != 1950 && _end.get(Calendar.YEAR) == 1950){
			return true;
		}
		return false;
	}

	public boolean isMisc(){
		if (_start.get(Calendar.YEAR) == 1950 && _end.get(Calendar.YEAR)== 1950){
			return true;
		}
		return false;
	}
}